package com.zipking.cloud.springbootmybatis.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Maps;
import com.zipking.cloud.springbootmybatis.model.PageReq;
import com.zipking.cloud.springbootmybatis.persistance.entity.MsgLog;
import com.zipking.cloud.springbootmybatis.persistance.mapper.MsgLogMapper;
import com.zipking.cloud.springbootmybatis.util.BatchQueryPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 通用分页查询工具类
 */
@Service
@Slf4j
public class BatchQueryPageUtilsService implements BatchQueryPageUtils {
    @Autowired
    private MsgLogMapper msgLogMapper;
    @Override
    public int queryTotalNum(Object queryParam) {
        LambdaQueryWrapper<MsgLog> queryWrapper = new LambdaQueryWrapper<MsgLog>();
        queryWrapper.eq(MsgLog::getRoutingKey, "XX");
        Integer totalCount = msgLogMapper.selectCount(queryWrapper);
        return totalCount;
    }

    @Override
    public List queryDataListByPage(PageReq queryDataParam) {

        Map<@Nullable String, @Nullable Object> map = Maps.newHashMap();
        map.put("limit", queryDataParam.getPageIndex());
        map.put("num", queryDataParam.getPageRows());
        return this.msgLogMapper.selectListByWhere(map);
    }

    @Override
    public void processLongTimeLogic(List list, Map otherParam) {

         log.info("list:{}",list.size());
    }
}
